package threading;

import java.util.Scanner;

public class ThreadDemo16 {
     //volatile关键字：被它修饰的变量会被禁止优化，
     volatile public static int flag = 0;
    public static void main(String[] args) {

        Thread t1 = new Thread( () -> {
            while (flag == 0) {

            }
            System.out.println(" 循环结束，t1线程结束");
        });
        Thread t2 = new Thread( () -> {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入一个整数");
            flag = sc.nextInt();

        });
        t1.start();
        t2.start();



    }
}
